package com.wujian.love.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: CommonUtils
 * @Description:
 * @Author: wuj
 * @Date: 2020-12-31 11:33
 **/
public class CommonUtils {

    /**
     * @Author wu
     * @Description //获取ip地址
     * @Date 11:33 2020/12/31
     * @Param [request]
     * @return java.lang.String
    **/
    public static String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        if ("0:0:0:0:0:0:0:1".equals(ip)) {
            ip = "127.0.0.1";
        }
        if (ip.split(",").length > 1) {
            ip = ip.split(",")[0];
        }
        return ip;
    }


}
